package com.showcai.tools.sms;

import com.showcai.tools.ToolsBase;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.AlibabaAliqinFcSmsNumSendRequest;
import com.taobao.api.response.AlibabaAliqinFcSmsNumSendResponse;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Baggio on 2017-11-21.
 */
public class SMSTools extends ToolsBase {

    private static final String SMS_FREE_SIGN_NAME = "秀才教育";
    private static final String SMS_TYPE = "normal";
    private static final String URL = "http://gw.api.taobao.com/router/rest";
    private static final String APPKEY = "23628936";
    private static final String SECRET = "dc0a371a6b2f5d87a14974708a5d9299";
    //预约验证码短信模板
    public static final String SMS_CODE = "SMS_144450731";
    //查询订单短信模板
    public static final String SMS_QUERY_CODE = "SMS_147418806";
    //预约成功通知短信模板
    public static final String SMS_NOTIFIY = "SMS_145591409";


    public static Map<String, String> sendSMS(String SMSParam, String RECNumber, String SMSTemplateCode) throws ApiException {
        TaobaoClient client = new DefaultTaobaoClient(SMSTools.URL, SMSTools.APPKEY, SMSTools.SECRET);
        AlibabaAliqinFcSmsNumSendRequest req = new AlibabaAliqinFcSmsNumSendRequest();
        req.setSmsType(SMS_TYPE);
        req.setSmsFreeSignName(SMS_FREE_SIGN_NAME);
        req.setSmsParamString(SMSParam);
        logger.info("sendSMSParam===>>>"+SMSParam);
        req.setRecNum(RECNumber);
        req.setSmsTemplateCode(SMSTemplateCode);
        AlibabaAliqinFcSmsNumSendResponse rsp = client.execute(req);
        logger.info(rsp.getSubMsg() + "rsp================>>>" + rsp.getErrorCode());
        Map<String, String> result = new HashMap<>();
        result.put("errorCode", rsp.getErrorCode());
        result.put("errorMSG", rsp.getSubMsg());
        return result;
    }

    public static void main(String[] args) {
      /*  String phone = "13618267496";
        String SMSParam = "{\"code\":\"123456\"}";
        try {
            SMSTools.sendSMS(SMSParam, phone, SMSTools.SMS_CODE);
        } catch (ApiException e) {
            e.printStackTrace();
        }*/
        String ss="xiucai_V1.0.0_2018_10_12.apk";
        String s[]=ss.split("\\.");
        System.out.println(s.length);
        for (int i=0;i<s.length;i++){
            System.out.println("s["+i+"]===>>"+s[i]);
        }
    }
}
